package com.egao.common.manage.company;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.company.entity.Company;
import com.egao.common.module.company.service.CompanyService;
import com.egao.common.module.cooperative.constants.CooperativeProjectConstants;
import com.egao.common.module.cooperative.entity.CooperativeProject;
import com.egao.common.module.cooperative.entity.CooperativeProjectActivity;
import com.egao.common.module.cooperative.entity.CooperativeProjectActivityStudent;
import com.egao.common.module.cooperative.entity.vo.CooperativeProjectActivityListVO;
import com.egao.common.module.cooperative.entity.vo.CooperativeProjectActivityStudentListVO;
import com.egao.common.module.cooperative.entity.vo.CooperativeProjectListVO;
import com.egao.common.module.cooperative.service.CooperativeProjectActivityService;
import com.egao.common.module.cooperative.service.CooperativeProjectActivityStudentService;
import com.egao.common.module.cooperative.service.CooperativeProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 产教融合 单位管理
 * @author root
 */
@Api(tags = "产教融合 单位管理")
@RestController
@RequestMapping("${api}")
public class CompanyCooperativeController extends BaseController {

    @Autowired
    private CompanyService companyService;
    @Autowired
    private CooperativeProjectService cooperativeProjectService;
    @Autowired
    private CooperativeProjectActivityService cooperativeProjectActivityService;
    @Autowired
    private CooperativeProjectActivityStudentService cooperativeProjectActivityStudentService;


    @PreAuthorize("hasAuthority('company:cooperative:list')")
    @ApiOperation(value = "产教融合项目列表")
    @ApiPageParam
    @GetMapping("/company/cooperative/page")
    public PageResult<CooperativeProjectListVO> page(HttpServletRequest request) {
        Company company = companyService.getByUserId(getLoginUserId());
        if (company == null) {
            return new PageResult<>();
        }

        PageParam<CooperativeProject> pageParam = new PageParam<>(request);
        pageParam.put("companyId", company.getId());
        return new PageResult<>(cooperativeProjectService.listPage(pageParam), pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('company:cooperative:list')")
    @ApiOperation(value = "产教融合项目详情")
    @GetMapping("/company/cooperative/detail")
    public JsonResult detail(Integer id) {
        return JsonResult.ok().setData(cooperativeProjectService.detail(id, CooperativeProjectConstants.RR_COMPANY));
    }

    @PreAuthorize("hasAuthority('company:cooperative:list')")
    @ApiOperation(value = "产教融合项目活动列表")
    @ApiPageParam
    @GetMapping("/company/cooperative/activity-page")
    public PageResult<CooperativeProjectActivityListVO> activityPage(HttpServletRequest request) {
        PageParam<CooperativeProjectActivity> pageParam = new PageParam<>(request);
        return new PageResult<>(cooperativeProjectActivityService.listPageActivity(pageParam), pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('company:cooperative:list')")
    @ApiOperation(value = "产教融合项目风采列表")
    @ApiPageParam
    @GetMapping("/company/cooperative/shine-page")
    public PageResult<CooperativeProjectActivityListVO> shinePage(HttpServletRequest request) {
        PageParam<CooperativeProjectActivity> pageParam = new PageParam<>(request);
        return new PageResult<>(cooperativeProjectActivityService.listPageShine(pageParam), pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('company:cooperative:list')")
    @ApiOperation(value = "产教融合项目工作动态列表")
    @ApiPageParam
    @GetMapping("/company/cooperative/dynamic-page")
    public PageResult<CooperativeProjectActivityListVO> dynamicPage(HttpServletRequest request) {
        PageParam<CooperativeProjectActivity> pageParam = new PageParam<>(request);
        return new PageResult<>(cooperativeProjectActivityService.listPageDynamic(pageParam), pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('company:cooperative:list')")
    @ApiOperation(value = "产教融合项目活动详情")
    @ApiPageParam
    @GetMapping("/company/cooperative/activity-detail")
    public JsonResult activityDetail(Integer id) {
        return JsonResult.ok().setData(cooperativeProjectActivityService.detail(id, CooperativeProjectConstants.RR_COMPANY));
    }

    @PreAuthorize("hasAuthority('company:cooperative:list')")
    @ApiOperation(value = "产教融合学生报名列表")
    @ApiPageParam
    @GetMapping("/company/cooperative/student-page")
    public PageResult<CooperativeProjectActivityStudentListVO> studentPage(HttpServletRequest request) {
        PageParam<CooperativeProjectActivityStudent> pageParam = new PageParam<>(request);
        return new PageResult<>(cooperativeProjectActivityStudentService.listPage(pageParam), pageParam.getTotal());
    }
}
